﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;

public class SwopModel : MonoBehaviour {
    // 兑换的物品信息
    public UILabel Title;
    public GameObject item;
    public UILabel Price;
    public UILabel Info;

    // 收件人信息
    public UIInput inputUserName;
    public UIInput inputUserPhone;
    public UIInput inputUserHome;

    // 按钮
    public GameObject ConfirmBtn;
    public GameObject CloseBtn;
    // id
    public int Id;

    EginUser user = EginUser.Instance;
    // Use this for initialization
    void Start () {
        UIEventListener.Get(ConfirmBtn).onClick = ButtonClick;
        UIEventListener.Get(CloseBtn).onClick = ButtonClick;
	}
	
	void ButtonClick(GameObject button)
    {
        if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
            PlayerPrefs.SetString("consigneeName", inputUserName.value);
            PlayerPrefs.SetString("consigneePhone", inputUserPhone.value);
            PlayerPrefs.SetString("consigneeHome", inputUserHome.value);
        }
        else if (button.name == "ConfirmBtn")
        {
            MallOrderRequest lg = new MallOrderRequest {GoodsId = Id,RealName = inputUserName.value,Telephone = inputUserPhone.value,Address = inputUserHome.value };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(lg, MsgId.MallOrderRequest);
        }
    }
}
